package com.lagou.mapper;

import com.lagou.pojo.Order;
import com.lagou.pojo.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IOrderMapper {
    /**
     * 查询订单及其所属用户
     * @return
     */
    List<Order> findOrderAndUser();


    /**
     * （一对一）
     * 首先查询order
     * 然后根据order的uid调用com.lagou.mapper.IUserMapper.findUserById去查询user封装到order实体中
     * @return
     */
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "ordertime", column = "ordertime"),
            @Result(property = "total", column = "total"),
            @Result(property = "user", column = "uid", javaType = User.class, one = @One(select = "com.lagou.mapper.IUserMapper.findUserById"))
    })
    @Select("select * from orders")
    List<Order> findOrderByAnnotation();


    /**
     * 根据id查询order
     */
    @Select("select * from orders where uid = #{uid}")
    List<Order> findOrderByUid(int uId);


}
